package com.abl.domain.model;

import java.text.MessageFormat;

/**
 * 全局错误处理
 */
public class AblError extends RuntimeException {
    //错误代码
    private int code = 500;
    //消息内容
    private String message = "操作失败";

    public AblError(String message) {
        this.message = message;
    }

    public AblError(String message, Object... argArray) {
        this.message = MessageFormat.format(message, argArray);
    }

    public AblError(int code) {
        this.code = code;
    }

    public AblError(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public AblError(AblMsg msg) {
        this.code = msg.getCode();
        this.message = msg.getMessage();
    }

    public SRS<Object> getResponse() {
        return SRS.byError().code(code).message(message);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

}
